<?php
/**
 * vanephp web framework
 * 视图工具类
 *
 * @author aray <ofree@qq.com>
 * @link http://www.vanephp.com/
 * @copyright Copyright &copy; 2010 aray
 * @license http://www.vanephp.com/license
 * @package core
 */

if ( ! defined ( 'INVANE' ) )
	exit ( '!' );

/**
 * 视图工具类
 * @author aray
 * @abstract
 */
abstract class view {
	public static $VARS = array ();
	private static $lang = '';
	/**
	 * 获取当前视图
	 */
	final public static function getViewer ( ) {
		return vane::singleton ( config::get ( 'view_class' ) );
	}
	/**
	 * 获取模板引擎
	 */
	final public static function getTpl ( ) {
		return self::getViewer ( )->getTpl ( );
	}
	/**
	 * 
	 * @param string $lang	语言包
	 */
	final public static function setLanguage ( $lang ) {
		self::$lang = $lang;
	}
	/**
	 * 获取视图缓存名称
	 */
	final public static function getCacheName ( ) {
		return 'VIEW-' . URI . '-(' . self::$lang . ')';
	}
	/**
	 * 是否缓存视图
	 */
	final public static function isCached ( ) {
		return self::getViewer ( )->isCached ( view::getCacheName ( ) );
	}
	/**
	 * 渲染视图
	 * @param string $tpl	模板
	 */
	final public static function display ( ) {
		return self::getViewer ( )->display ( );
	}
	/**
	 * 设置模板变量
	 * @param array $vars	模板变量
	 */
	final public static function assign ( $vars ) {
		self::$VARS = array_merge ( self::$VARS, $vars );
	}
}